<?php

/* Main controller for backend */

class Admin extends Controller
{
    function Admin()
    {
        parent::Controller();
        $this->load->library('constants');
    }
    
    function index()
    {
        //Check if the user is currently logged in
        //In the base implementation this relies on cookie-based session (encryped)
        //So it is not really secure
        //TODO: Fix it!
        $is_logged_in = $this->session->userdata('authorized');
        if ($is_logged_in == FALSE || $is_logged_in != $this->constants::$authorized) {
            $this->load->view('login');
        }
        else {
            $user_type = $this->session->userdata('user_type');
            if ($user_type == $this->constants::$admin) {
                $this->load->view('admin_main_interface');
            }
            elseif (($user_type == $this->constants::$publisher) {
                $this->load->view('publisher_main_interface');
            }
        }
    }
}

?>